<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <!-- 请购人（模糊查询），单据编号，需求日期（开始，结束），采购类型，公司部门（级联选择框） -->
        <el-form-item>
          <el-input v-model="filters.psnname" placeholder="请购人"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="filters.orderNum" placeholder="单据编号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="filters.needDayStart"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="需求开始日期"
          ></el-date-picker>-
          <el-date-picker
            v-model="filters.needDayStop"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="需求结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-date-picker
                  v-model="filters.submitTimeStart"
                  value-format="yyyy-MM-dd"
                  type="date"
                  placeholder="已购买提交开始日期"
          ></el-date-picker>-
          <el-date-picker
                  v-model="filters.submitTimeStop"
                  value-format="yyyy-MM-dd"
                  type="date"
                  placeholder="已购买提交结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-select v-model="filters.buyType" placeholder="采购类型">
            <el-option label="紧急采购" value="0"></el-option>
            <el-option label="零星采购" value="1"></el-option>
            <el-option label="合同采购" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getList">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <!--列表-->
    <el-table
      :data="formList"
      highlight-current-row
      v-loading="listLoading"
      @selection-change="selsChange"
      style="width: 100%;"
      height="50vh"
    >
      <el-table-column prop="orderNum" label="单据编号" align="center"></el-table-column>
      <el-table-column prop="uploadDay" label="请购日期" align="center"></el-table-column>
      <el-table-column prop="needDay" label="需求日期" align="center"></el-table-column>
      <el-table-column prop="buyType" label="采购类型" :formatter="formatterBuyType"></el-table-column>
      <el-table-column prop="unitname" label="公司"></el-table-column>
      <el-table-column prop="deptname" label="部门"></el-table-column>
      <el-table-column prop="psnname" label="请购人"></el-table-column>
      <el-table-column prop="singlePerson" label="制单人"></el-table-column>
      <el-table-column prop="submitTime" label="已购买提交时间"></el-table-column>
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :page-size="page.pageSize"
        :total="total"
        style="float:right;"
      ></el-pagination>
    </el-col>
  </section>
</template>

<script>
import util from "../../common/js/util";
import {
  wlcOrderList,
  wlcSysInquiryRemove,
} from "../../api/api";
import {
  companyList,
  omJobSelectBdDeptdoc,
  omJobSelectBdCorp,
} from "../../api/baseSetting";
export default {
  components: {},
  data() {
    return {
      filters: {
        psnname: "",
        orderNum: "",
        needDayStart: "",
        needDayStop: "",
        buyType: "",
        submitTimeStop: ""
      },
      formList: [],
      total: 0,
      page: {
        page: 1,
        pageSize: 10,
      },
      listLoading: false,
      sels: [], //列表选中列
    };
  },
  methods: {
    getCompanyDepart(e) {
      this.filters.unitnameId = e[2].value;
      this.filters.deptnameId = e[3].pkDeptdoc;
    },
    //格式化采购类型
    formatterBuyType(e) {
      let buyType = e.buyType;
      let text = "";
      switch (buyType) {
        case 0:
          text = "紧急采购";
          break;
        case 1:
          text = "零星采购";
          break;
        case 2:
          text = "合同采购";
          break;
        default:
          text = "";
      }
      return text;
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.getList();
    },
    //获取列表
    getList() {
      let para = Object.assign({}, this.filters);
      para.page = this.page;
      this.listLoading = true;
      wlcOrderList(para).then((res) => {
        this.total = res.total;
        this.formList = res.records;
        this.listLoading = false;
      });
    },
    //跳转详情界面
    handleEdit(index, row) {
      this.$router.push({
        path: "purchaseOrderDetial",
        query: {
          id: row.id,
        },
      });
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
  },
  mounted() {
    this.getList();
  },
};
</script>
<style lang="less" scoped>
</style>
